package com.nf.health.app.intervention_details.fragment;


import android.os.Bundle;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.nf.health.app.Constants;
import com.nf.health.app.R;
import com.nf.health.app.core.MyGsonBuilder;
import com.nf.health.app.fragment.IBaseFragment;
import com.nf.health.app.http.Act;
import com.nf.health.app.intervention_details.adapter.FollowupAdapter;
import com.nf.health.app.intervention_details.adapter.HealthImproveDetailsAdapter;
import com.nf.health.app.intervention_details.bean.ImproveDetailsBean;
import com.nf.health.app.intervention_details.bean.QuestionListBean;
import com.nf.health.app.utils.ViewUtil;

import java.lang.reflect.Type;
import java.util.ArrayList;

/**
 * 健康行动改善指南 方案详情
 *
 * @author changpeng 16/11/10
 */
public class HealthImproveDetailsFragment extends IBaseFragment {
    private RecyclerView mRecyclerView;
    private HealthImproveDetailsAdapter mHealthImproveDetailsAdapter;
    private ImproveDetailsBean mImproveDetailsBean;

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        addViewFillInRoot(R.layout.common_layout_recycler);
        mRecyclerView = ViewUtil.getView(rootView,R.id.recycler_view_common);
        mRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
        initData();
    }

    private void initData(){
        provider.getInterveneHealthAction(Constants.CHANGE_ABLE.INTERVENTION_ID);
    }
    @Override
    public void handleActionSuccess(String actionName, Object object) {
        if(actionName.equals(Act.Flag.GET_INTERVENE_HEALTH_ACTION)){
            Gson gson = new MyGsonBuilder().createGson();
            mImproveDetailsBean = gson.fromJson(object+"",ImproveDetailsBean.class);
            if(mImproveDetailsBean == null){
                return;
            }
            mHealthImproveDetailsAdapter = new HealthImproveDetailsAdapter(getContext(),mImproveDetailsBean);
            mRecyclerView.setAdapter(mHealthImproveDetailsAdapter);
        }
    }
}
